package com.pan.note.im.config;

import com.pan.note.im.dto.GameRoomDto;
import com.pan.note.im.enumerate.RedisDataEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.PostConstruct;

@Configuration
public class RoomConfig {

    @Autowired
    private RedisTemplate redisTemplate;

    @PostConstruct
    public void loadRoom(){
        //启动时加载游戏房间，先暂时加载9个房间
        for (int i = 0; i < 9; i++) {
            GameRoomDto gameRoomDto = new GameRoomDto();
            gameRoomDto.setRoomId(i+1);
            redisTemplate.opsForHash().put(RedisDataEnum.GAMEROOM.getMsg(),String.valueOf(i+1),gameRoomDto);
        }
    }
}
